package next_flag_search;

import env.Action;
import java.util.LinkedList;

/**
 *
 * @author user
 */
public class IDS extends Search {

    int maxDepth = 1;

    @Override
    public LinkedList<Action> search() {
        maxDepth = 1;
        LinkedList<Action> ans = null;
        while (maxDepth< 1000 && ans == null) {
            MyQueue q = new MyQueue() {

                LinkedList<Node> queue = new LinkedList<Node>();

                public Node poll() {
                    return queue.removeFirst();
                }

                public void add(Node n) {
                    if (n.getDepth() <= maxDepth) //<------------------------ only diff from DFS
                    {
                        queue.addFirst(n);
                    }
                }

                public boolean isEmpty() {
                    return queue.isEmpty();
                }
            };
            ans = graphSearch(q);
            maxDepth++;
        }
        System.out.println("@@@@ IDS found a plan for depth " + maxDepth + " @@@@");
        return ans;
    }
}
